import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { ScheduleModule } from '@nestjs/schedule'
import { MeetingRoomModule } from '@/modules/meeting-room/meeting.module'
import { ConfigModule, ConfigService } from '@nestjs/config'
import developmentConfig from '@/config/development.config'
import productionConfig from '@/config/production.config'
import { DeployModule } from '@/modules/deploy/deploy.module'

const { NODE_ENV = 'development' } = process.env
@Module({
  imports: [
    DeployModule,
    ScheduleModule.forRoot(),
    MeetingRoomModule,
    ConfigModule.forRoot({
      load: [NODE_ENV === 'development' ? developmentConfig : productionConfig]
    }),
    MongooseModule.forRootAsync({
      imports: [ConfigModule], // 导入 ConfigModule 以便访问 ConfigService
      useFactory: async (configService: ConfigService) => ({
        uri: `mongodb://${configService.get('database.user')}:${configService.get('database.password')}@${configService.get('database.host')}:${configService.get('database.port')}/${configService.get('database.database')}?authSource=admin`
      }),
      inject: [ConfigService] // 注入 ConfigService
    })
  ]
})
export class AppModule {}
